using System;
using System.Collections.Generic;
using System.Text;

namespace Logic.Agglomerative
{
    /// <summary>
    /// A static class that have a function to merge two nodes into 
    /// new node according to the merge type.
    /// </summary>
    public static class MergeFunction
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="type"></param>
        /// <param name="fatherName"></param>
        /// <returns></returns>
        public static Node merge(Node FirstNode, Node SecondNode,int type,int fatherName)
        {
            if ((FirstNode != null) && (SecondNode != null))
            {
                switch (type)
                {
                    case 1:
                        return new Node(FirstNode.I, fatherName, Math.Min(FirstNode.Key, SecondNode.Key));
                    case 2:
                        return new Node(FirstNode.I, fatherName, Math.Max(FirstNode.Key, SecondNode.Key));
                    case 3:
                        return new Node(FirstNode.I, fatherName, (FirstNode.Key + SecondNode.Key) / 2);
                }
            }
            return null;
        }
    }
}
